#include <iostream>
#include <vector>
#include <climits>

using namespace std;

struct Edge {
    int start{};
    int end{};
    int weight{};
};

const int UNKNONW = INT_MAX;

int BellmanFord(int N, const vector<Edge>& edges) {
    vector<int> distance(N + 1, UNKNONW);
    distance[0] = 0;
    for (int i = 0; i < N - 1; ++i) {
        for (const auto& e : edges) {
            if (distance[e.start] == UNKNONW)
                continue;
            if (distance[e.start] + e.weight < distance[e.end])
                distance[e.end] = distance[e.start] + e.weight;
        }
    }
    //检查负循环
    for (const auto& e : edges) {
        if (distance[e.start] == UNKNONW)
            continue;
        if (distance[e.start] + e.weight < distance[e.end])
            return UNKNONW;
    }
    return distance[N - 1];
}

int main(int argc, const char** argv) {
    int N;
    cin >> N;
    vector<Edge> edges;
    edges.reserve(N * N);
    for (int i = 0; i < N * N - 1; ++i) {
        string directions;
        int power;
        cin >> directions >> power;
        for (auto d : directions) {
            int next; //输入数据保证不越界
            switch (d) {
                case 'N': next = i - N; break;
                case 'E': next = i + 1; break;
                case 'S': next = i + N; break;
                case 'W': next = i - 1; break;
            }
            edges.emplace_back(Edge{i, next, -power});
        }
    }
    int result = BellmanFord(N * N, edges);
    if (result == UNKNONW)
        cout << "TRAVERSAL ABORTED\n";
    else
        cout << -result << endl;
    return 0;
}